const request = require('superagent')
const multer = require('@koa/multer');
//
const upload = multer({
   limits: { fileSize: 500 * 1024 * 1024 } // 将文件大小限制设置为200MB
});
module.exports = {
    entry: function (app, router, opts) {
        let decryption= async (ctx, next) => {
            try {
               const { xunruan } = opts
               const { file } = ctx.request
               let url = `${xunruan.host}/uploadSecret`;
               let res_ = await request.post(url).set('Content-Type', 'application/octet-stream')
                  .send(file.buffer)
                  .responseType('binary')
         
               ctx.status = 200;
               ctx.body = res_.body
            } catch (error) {
               ctx.status = 400;
               ctx.body = { message: 'decryption error.' };
            }
         }
      router.post("/xunruan/decryption",upload.single('file'),  decryption,{ content: '讯软解密', visible: false });
    },
  };